package main

import (
	"fmt"
	"strings"
)

// 从通道里面读取值，直到它关闭为止。
// 可以使用 range 关键字达到该目的
func main() {
	c0 := make(chan string)
	c1 := make(chan string)
	go sourceGopher(c0)
	go filterGopher(c0, c1)
	printGopher(c1)
}
func sourceGopher(downstream chan string) {
	for _, v := range []string{"hello world", "a bad apple", "goodbye all"} {
		downstream <- v
	}
	close(downstream)
}
func filterGopher(upstream, downstream chan string) {
	for item := range upstream {
		if !strings.Contains(item, "bad") {
			downstream <- item
		}
	}
	close(downstream)
}
func printGopher(upstream chan string) {
	for v := range upstream {
		fmt.Println(v)
	}
}
